<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Function</title>
    <script>
        function callComeFunction(someFunction, arguments) {
            return someFunction(arguments);
        }

        function add10(num) {
            return num + 10;
        }
        //因为要访问的是函数的指针，而函数名本身就是一个变量，所以此处要传递add10，而不是add10()
        let result = callComeFunction(add10, 10);
        console.log("result: " + result);//20


        /**
         * 将函数作为返回值
         */
        function creatComparsion(propertyName) {

            return function (obj1, obj2) {
                let vaule1 = obj1[propertyName];//根据属性名访问对象的属性
                let vaule2 = obj2[propertyName];

                if (vaule1 < vaule2) {
                    return -1;
                }else if (vaule1 > value2) {
                    return 1;
                } else {
                    return 0;
                }

            };
            
        }


        let  students = [{name : "zhangsan", age: 25}, {name: "lisi", age: 30}]

        let resultCompareByName = students.sort(creatComparsion("name"));//按名字排序
        console.log(students[0].name)//李四
        let resultCompareByAge = students.sort(creatComparsion("age"));//按年龄排序
        console.log(students[0].name);//张三


    </script>
</head>
<body>
作为值得函数
</body>
</html>